﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TeBigCoreApi.Common;
using TeBigCoreApi.Models;

namespace TeBigCoreApi.Controllers
{
    [Produces("application/json")]
    [Route("api/Dept")]
    public class DeptController : Controller
    {
        [Route("Stat")]
        [HttpPost]
        public QueryDeptStatResponse QueryDeptStat([FromBody]QueryDeptStatRequest req)
        {
            var resp = new QueryDeptStatResponse();

            try
            {
                foreach (var item in DeptManager.Stations)
                {
                    resp.List.Add(new DeptStat
                    {
                        AxisX = item.Name,
                        AxisY = MyRandom.NextInt(10, 50),
                        Weight = MyRandom.NextDouble(1, 100),
                        Coord = new CoordData {
                            Longitude = item.Longitude,     //MyRandom.NextDouble(123.77777, 125.83382),
                            Latitude = item.Latitude,       //MyRandom.NextDouble(45.33044, 47.48064),
                        }
                    });
                }

                resp.OnSuccess();
            }
            catch (Exception ex)
            {
                resp.OnException(ex);
            }

            return resp;
        }
    }
}